<template>
  <div class="wrapper_project">
     <div v-if="title=='新指派我的' && count != 0" class="count">
       <el-badge :value="count" class="itemCount" >
      </el-badge>
  </div>
     <div v-if="title=='日报待评审'&& count != 0 " class="count">
       <el-badge :value="count" class="itemCount" >
      </el-badge>
     </div>
    <div class="title " v-if="!isShow">{{ title }}</div>
    <div class="title changes" v-else>
      <span>项目人力报表</span>
      <span class="end">(以下为本月初开始至今天每个员工的稼动情况)</span>
    </div>
    <div>
       <div class="table">
       <el-table
        :header-cell-style="tableHeaderStyle"
        :data="tableData"
        :style="'width:' + width"
        border
        :cell-style="{ textAlign: 'center' }"
        :cell-class-name="addclass"
        :max-height="500"
      >
      <template slot="empty">
        <img src="../../../img/img_01@3x.png" alt="" style="width:88px;height:58px;margin-top:50px">
        <div style="margin-bottom:20px;padding-right:15px;margin-top:-30px">暂无数据</div>
      </template>
        <el-table-column v-for="(item, index) of columns" :key="index" :label="item.label" :prop="item.prop" min-width="88" show-overflow-tooltip>
          <template slot-scope="scope" >
            <span @click="test(scope.row)">{{ scope.row[item.prop] }} </span>
          </template>
        </el-table-column>
        <el-table-column label="项目当前进度" v-if="isPercent" >
          <template slot-scope="scope">
            <el-progress :text-inside="false" :stroke-width="10" :percentage="scope.row.progress != null ? Number(scope.row.progress) : 0" style="text-align: left"></el-progress>
          </template>
        </el-table-column>
        <el-table-column label="操作"  fixed="right" v-if="customerRender" min-width="120" align="center">
          <template slot-scope="scope" >
            <div class="operation">
                <el-button v-if="scope.row.isProManager == null" type="text" class="viewDetail">
                    <span  @click="enterDetail(scope.row,'btnDetail')"> {{ customerText }} </span>
                </el-button>
                <el-button v-if="scope.row.isProManager" type="text" class="viewDetail">
                    <span  @click="enterDetail2(scope.row,'btnDetail')"> {{ customerText }} </span>
                </el-button>
                <el-button v-if="scope.row.isProManager != null && !scope.row.isProManager" type="text" class="viewDetail">
                    <span  @click="enterDetail2(scope.row,'btnDetail')"> {{ '查看' }} </span>
                </el-button>
            <el-button type="text" class="viewDetail" @click="enterDetail(scope.row,'btnEdit')" v-if="title == '项目概况' && editAudit(scope.row)">
              {{ customerText2 }}
            </el-button>
            <el-button type="text" class="viewDetail" v-if="title == '项目概况' && changesAudit(scope.row)" @click="enterDetail(scope.row,'btnChange')">
              {{ customerText3 }}
            </el-button>
            <el-button type="text" class="viewDetail" v-if="title == '项目概况' && finishAudit(scope.row) && scope.row.isAssignment == false " @click="distribution(scope.row)">
              分配
            </el-button>
            <el-button type="text" class="viewDetail" v-if="title == '项目概况' && changesAudit(scope.row)" @click="gotoSetReview(scope.row)">
                设置
            </el-button>
            <el-button type="text" class="viewDetail" v-if="title == '项目概况' && finishAudit(scope.row)" @click="finishPro(scope.row)">
              完成
            </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>

        <div  v-if="pagination" style="display: flex;justify-content: end;margin-top: 14px;">
        <el-pagination
          layout="prev, pager, next"
          :total="1000"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        >
        </el-pagination>
        </div>

        </div>


    </div>

  </div>
</template>

<script>
    import {tableHeaderStyle} from '@/utils/constant'
export default {
  data() {
    return {
      tableHeaderStyle: {
        ...tableHeaderStyle,
        textAlign: 'center'
      },
      roleNames: '',
      currentUsedId: ''
    }
  },
  props: {
      pagination:{
        type:Boolean,
        default:false
      },

    tableData: {
      type: Array,
      default() {
        return []
      }
    },
    columns: {
      type: Array,
      default() {
        return []
      }
    },
    customerRender: {
      type: Boolean,
      default: true
    },
    customerText: {
      type: String,
      default: '查看'
    },
    customerText2: {
      type: String,
      default: '编辑'
    },
    customerText3: {
      type: String,
      default: '变更'
    },
    customerText4: {
      type: String,
      default: '立即分配'
    },
    title: {
      type: String,
      default: ''
    },
      width: {
          type: String,
          default: '100%'
      },
    isPercent: {
      type: Boolean,
      default: true
    },
    count: {
        type: [Number, String],
        default: 0
    },
      btnEdit:{
        type:Boolean,
          default:false
      },
      btnDetail:{
          type:Boolean,
          default:true
      },
      btnChange :{
         type:Boolean,
        default:false
      },

  },
  watch:{
      tableData:{
          handler(newData,oldData){
              // console.log(newData)
          }
      }
  },
  mounted() {
    const user = localStorage.getItem('user')
    this.roleNames = this.$store.state.user.roleNames || (user && JSON.parse(user).roleNames) || ''
    this.userId = (user && JSON.parse(user).userId) || ''
  },

    computed: {
    editAudit: function() {
      return function(item) {
        const flag = this.roleNames.includes('部门主管') && item.status == '待审批' && item.createUserId == this.userId
        return flag
      }
    },
    changesAudit: function() {
      return function(item) {
        const flag = this.roleNames.includes('项目经理') && item.proManager == this.userId && item.status == '进行中'
        return flag
      }
    },
    finishAudit: function() {
      return function(item) {
        const flag = this.roleNames.includes('项目经理') && item.proManager == this.userId && item.status == '进行中'
        return flag
      }
    },
    // 文字是否是项目人天报表
    isShow: function () {
      return this.title && this.title.includes('稼动')
    },

  },
  methods: {

      // 子组件页面切换
      test(val){
          // console.log(val)
      },
      handleSizeChange(val) {
          // console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {

      },
    enterDetail(item,type) {
      this.$emit("enterDetail",item,type)
    },
      enterDetail2(item,type) {
          this.$emit(item.isProManager?"enterDetail" : "enterDetail2",item,type)
      },
    addclass(row){
        if (row.column.label == '操作') {
            return 'text-left'
        }
    },
    // 完成项目
    finishPro(item) {
        this.$confirm('确定该项目已完结？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            this.$emit('finishPro', item.proId)
            this.$message({
                type: 'success',
                message: '完成成功!'
            });
        }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消'
            });
        });
    },
    // 再分配
    distribution(item) {
      this.$emit('distribution', item)
    },
    gotoSetReview(obj){
        this.$router.push("/review?proId="+obj.proId)
    }

  }
}
</script>

<style lang="scss" scoped>
.wrapper_project{
  display: flex;
  flex-direction: column;
  margin-top: 20px;
  .title{
    // padding-left: 20px;
    margin-bottom: 20px;
    white-space: pre;
  }
}
.defaultCircle{
  position: relative;
  &::before{
    position: absolute;
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #7F7F7F;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
  }
}
.changes{
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  .end{
    margin-left: 20px;
    font-size: 16px;
    color: #999999;
  }
}
.operation{
  display: flex;
  flex-direction: row;
  justify-content: center;
  flex-wrap: nowrap;
  .viewDetail{
    margin-right: 10px;
    min-width: 20px;
  }
}
</style>
<style>
  .text-left{
    text-align: left !important;
  }
</style>

<style lang="less" scoped>
    ///deep/.el-progress-bar__inner{
    //    text-align: left;
    //}
    /deep/.el-progress__text{
        font-size: 10px !important;
        //width: 40px;
    }
    /deep/.el-pagination{
      white-space: nowrap;
    padding: 2px 5px;
    color: #303133;
    font-weight: 700;
    background: white;
    }
    .count{
      position: relative;
  }
  .itemCount{
      position: absolute;
      left:80px;
      top:0px
  }
//   /deep/body .el-table th.gutter {
//    display: table-cell!important;
// }

    /deep/body .el-table th.gutter {
        display: table-cell!important;
    }

    /deep/.el-progress-bar{
        width: 95%;
    }

</style>
